import { Component } from 'react';
import React from 'react';
import { connect } from 'umi';
import HighPerformTable from '@/components/HighPerformTable';
import { GetUserList } from '@/apis/UserAPIs';
import APIS from '@/apis';

class UserListPage extends Component<any, any> {
  actionRef: any;

  constructor(props: any) {
    super(props);
  }

  componentDidMount() {}

  handleModalVisible(value: boolean) {}
  setSelectedRows(rows: Array<any>) {}
  handleRemove(data:any) {
    return APIS.UserAPI.DeleteUser(data)
      .then(() => {
        return Promise.resolve(true);
      })
      .catch(() => {
        return Promise.resolve(false);
      });

  }
  handleAdd(data:any) {
    return Promise.resolve(true);
  }
  handleUpdateModalVisible(value: boolean) {}
  handleUpdate(data:any) {
    return Promise.resolve(true);
  }
  clomns: any = [
    {
      title: '用户名',
      dataIndex: 'name',
      rules: [
        {
          required: true,
          message: '规则名称为必填项',
        },
      ],
    },
    {
      title: '昵称',
      dataIndex: 'nickname',
      valueType: 'text',
      rules: [
        {
          required: true,
          message: '昵称为必填项',
        },
      ],
    },
    {
      title: '手机号码',
      dataIndex: 'phone',
      rules: [
        {
          required: true,
          message: '手机号码为必填项',
        },
      ],
    },
    {
      title: '性别',
      dataIndex: 'gender',
      sorter: true,
      rules: [
        {
          required: true,
          message: '性别为必填项',
        },
      ],
      valueEnum: {
        0: { text: '保密', status: 'Default' },
        1: { text: '男', status: 'Processing' },
        2: { text: '女', status: 'Success' },
      },
    },
    {
      title: '邮箱',
      dataIndex: 'email',
      valueType: 'email',
      rules: [
        {
          required: true,
          message: '邮箱为必填项',
        },
      ],
    },
    {
      title: '角色分配',
      dataIndex: 'email',
      valueType: 'email',
      rules: [
        {
          required: true,
          message: '邮箱为必填项',
        },
      ],
      render:()=>{
        return <a>查看/修改</a>
      }
    },
  ];

  requestGetData(
    params: {
      pageSize?: number;
      current?: number;
    },
    sorter: {
      [key: string]: 'ascend' | 'descend';
    },
    filter: {
      [key: string]: React.ReactText[];
    },
  ) {
    return GetUserList({ ...params, sorter, filter });
  }
  handleChangeState(record: any, state: boolean) {
    return APIS.UserAPI.ChangeUserState({ id: record.id, state: state ? 1 : 0 }).then(
      (response) => {
        return Promise.resolve(response.data.state === 1);
      },
    );
  }
  render() {
    return (
      <div>
        {/* <KeywordFilterSearch
          filters={[
            { title: '角色类型', multiple: false, keywords: ['全部', '教务管理员', '教师'] },
          ]}
        ></KeywordFilterSearch> */}
        <HighPerformTable<any>
          ref={(ref) => (this.actionRef = ref)}
          columns={this.clomns}
          handleChangeState={this.handleChangeState.bind(this)}
          handleUpdate={this.handleUpdate.bind(this)}
          handleDelete={this.handleRemove.bind(this)}
          toolBarRender={() => [
            // <Button type="primary" onClick={() => this.actionRef.handleModalVisible(true)}>
            //   <PlusOutlined /> 新增用户
            // </Button>,
          ]}
          requestGetData={this.requestGetData.bind(this)}
        />
      </div>
    );
  }
}

export default connect()(UserListPage);


